import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { SourceQuery, SourceItem, SourceForm } from "./types";

/**
 *
 * @param queryParams
 * @returns
 * @description 获取SourceTree
 *
 **/
export function getSourceTree(
  queryParams?: SourceQuery
): AxiosPromise<SourceItem[]> {
  return request({
    url: "/api/system.source/getTree",
    method: "get",
    params: queryParams,
  });
}

/**
 * @param data
 * @returns
 * @description 创建Source
 **/
export function createSource(data: SourceForm) {
  return request({
    url: "/api/system.source/create",
    method: "post",
    data: data,
  });
}

/**
 * @param id
 * @returns
 * @description 删除Source
 **/
export function deleteSource(id: number) {
  return request({
    url: "/api/system.source/delete/id/" + id,
    method: "delete",
  });
}

/**
 * @param id
 * @returns
 * @description 获取Source
 **/
export function getSource(id: number): AxiosPromise<SourceForm> {
  return request({
    url: "/api/system.source/read/id/" + id,
    method: "get",
  });
}

/**
 * @param id
 * @param data
 * @returns
 * @description 更新Source
 **/
export function updateSource(id: number, data: SourceForm) {
  return request({
    url: "/api/system.source/save/id/" + id,
    method: "put",
    data: data,
  });
}
